// 导入ex模块 web的框架,
const express = require('express')
const { userList,adduser ,updateUser} = require('./user_data')
//2.创建路由对象
const router = express.Router()
// 用户列表
router.get('/userlist', (request, response) => {
  // console.info('get方法获取到了', request.query)
  // console.info('get方法获取到了', request.params)
  let back = {
    "total": userList.length,
    "rows": userList,
    "code": 200,
    "msg": "查询成功"
  }
  response.send(back)
})
// 获取默认用户
router.get('/user/default', (request, response) => {
  // console.info('get方法获取到了', request.query)
  // console.info('get方法获取到了', request.params)
  let back = {
    "data": userList[0],
    "code": 200,
    "msg": "查询成功"
  }
  response.send(back)
})
// 添加用户
router.get('/adduser', (request, response) => {
  let user =  request.query
  user = adduser(user)
  let back = {
    "data": user,
    "code": 200,
    "msg": "查询成功"
  }
  response.send(back)
})
// 更新用户
router.get('/updateuser', (request, response) => {
  let user = JSON.parse(request.query.model) 
  user = updateUser(user)
  let back = {
    "data": user,
    "code": 200,
    "msg": "查询成功"
  }
  response.send(back)
})
//向外导出路由对象
module.exports = router